<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="../../../include/taglibs.jsp"%>
<%@ include file="../../../include/ext.jsp"%>
<!DOCTYPE HTML>
<html>
	<head>
        <link href="${basePath}/admin/main_page/css/main.css" rel="stylesheet">
		<META http-equiv=Content-Type content="text/html; charset=UTF-8">
		<title>客户关系管理系统</title>
		<script Language="JavaScript">
		Date.prototype.format = function(format) {  
		     var o = {  
		         "M+" :this.getMonth() + 1, // month  
		         "d+" :this.getDate(), // day  
		         "h+" :this.getHours(), // hour  
		         "m+" :this.getMinutes(), // minute  
		         "s+" :this.getSeconds(), // second  
		         "q+" :Math.floor((this.getMonth() + 3) / 3), // quarter  
		         "S" :this.getMilliseconds()  
		     }  
		     if (/(y+)/.test(format)) {  
		         format = format.replace(RegExp.$1, (this.getFullYear() + "")  
		                 .substr(4 - RegExp.$1.length));  
		     }  
		     for ( var k in o) {  
		         if (new RegExp("(" + k + ")").test(format)) {  
		             format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]  
		                     : ("00" + o[k]).substr(("" + o[k]).length));  
		         }  
		     }  
		     return format;  
		 }
		 
		 String.prototype.replaceAll = function(s1,s2) {
			    return this.replace(new RegExp(s1,"gm"),s2);
			}		
			String.prototype.contains = function(str) { 
			    return this.indexOf(str) > -1 ? true : false; 
			}
		var basepath ='${basePath}';
		var basePath ='${basePath}';
		var realName ='${sysMember.realName}';
		var sysMemberId_8 = '${sysMemberId}';
        Ext.override(Ext.menu.DateMenu, {
            render : function() {
                Ext.menu.DateMenu.superclass.render.call(this);
                if (Ext.isGecko || Ext.isSafari) {
                    this.picker.el.dom.childNodes[0].style.width = '178px';
                    this.picker.el.dom.style.width = '178px';
                }
            }
        });
		</script>
	</head>
	<body>
		<script type="text/javascript" src="${basePath}/admin/main_page/js/main.js"></script>
		<script type="text/javascript" src="${basePath}/admin/main_page/js/constant.js"></script>
        <%@ include file="../../../include/js_j.jsp"%>
        <%@ include file="../../../include/js_min.jsp"%>
<script>

var sysModeLoader = new Ext.data.JsonStore({
	url:basepath+"/yft/yftCrmLogin/getNextMenus.html",
	root:'root',
	totalProperty:'totalProperty',  
	fields:[
			{name: 'id'},
			{name: 'name'},
			{name: 'upId'},
			{name: 'panelName'}
	]  
});	
var root = new Ext.tree.TreeNode({
	id:'root',
	draggable : false,
	expanded : true
});
		
var secondTreePanel = new Ext.tree.TreePanel({
	root:root,
	animate: false,
	border : false,
	autoHeight : false,
	rootVisible : false,
	autoScroll:false,
	enableDD:false
});
secondTreePanel.on('contextmenu',function(node,e){e.preventDefault();node.fireEvent('click',node,e);})

bookPanel = function() {
	bookPanel.superclass.constructor.call(this, {
		title: '菜单',
		region : 'west',
		id:'menuPanelId',
		width : 170,
		collapsible : true,
		frame:false,
		minSize : 200,
		//split : true,
		margins : '0 0 3 0',
		items : [secondTreePanel]
	});
}

Ext.onReady(function() {
	Ext.getBody().dom.oncontextmenu = function(e){
		window.event ? window.event.returnValue = false : e.preventDefault(); 
	};
    function isContainChinese(str){
        if(/.*[\u4e00-\u9fa5]+.*$/.test(str))
        {
            return true;
        }
        return false;
    }
    Ext.Ajax.timeout = 60000;//ajax超时时间
	//登录超时和无权限时的配合事件
	Ext.Ajax.on("requestcomplete",function(conn,response,options){
	    if(response.getResponseHeader && typeof response.getResponseHeader.sessionstatus != "undefined"){ 
			var resposeStatus = response.getResponseHeader.sessionstatus;
			resposeStatus = resposeStatus.replace(/\s/g,"");
			if(resposeStatus=="timeout"){
				window.location.replace("${basePath}/auth/login.html");  
				return;
			}
		}
		
		var m = Ext.decode(response.responseText);
		if(m.competenceError){
			Ext.MessageBox.alert("提示",m.msg);
			return;
		}
		if(m.jsonStoreLoadError){
            var mes = m.msg;
            if(Ext.isEmpty(mes) ||  !isContainChinese(mes))
                mes = "操作失败";
			Ext.MessageBox.alert("提示",mes);
			return;
		}
	}, this);
	Ext.Ajax.on("requestexception",function(conn, response, options){
		Ext.MessageBox.alert("错误","连接服务器出错，请稍后重试！");
		return;
	}, this);
	Ext.QuickTips.init();
	Ext.form.Field.prototype.msgTarget = 'qtip';
	Ext.BLANK_IMAGE_URL = basePath+'/ext/resources/images/default/s.gif';
	main = new tabContent();
	// 主面板
	var showPort;
	
	Ext.extend(bookPanel, Ext.Panel);
	
	menu = new bookPanel();
	
	showPort = new Ext.Viewport({
		enableTabScroll : true,
		layout : 'border',
		modal : true,
		items : [header, main]
	});
	
	<c:if test="${!isHasMenuCompetence}">
			Ext.Msg.alert("提示","对不起,您当前没有任何菜单的权限,请联系管理员添加!");
	</c:if>
	<c:if test="${isHasMenuCompetence}">
        var cn = root.childNodes,
            n;
        while((n = cn[0])){
            root.removeChild(n);
        }
        <c:forEach items="${sysCompetenceMenuList}" var="tmp" varStatus="s">
            <c:if test="${tmp.upId==0}">
                baseNode =new Ext.tree.TreeNode({
                    id:'${tmp.sysCompetenceId}',
                    upId:'${tmp.upId}',
                    text:'${tmp.name}',
                    listeners : {
                        'click' : function(node, event) {
                            <c:if test="${!empty tmp.panelName}">
                                callWeb(node, event, '',${tmp.panelName})
                            </c:if>
                            if(node.hasChildNodes()){
                                if(this.expanded){
                                    this.collapse();
                                }else{
                                    this.expand();
                                }
                            }
                         }
                    }
                });
                root.appendChild(baseNode);
            </c:if>
            <c:if test="${tmp.upId!=0}">
                root.eachChild(function(child){
                    if(child.id=='${tmp.upId}'){
                        child.appendChild(new Ext.tree.TreeNode({
                            id:'${tmp.sysCompetenceId}',
                            upId:'${tmp.upId}',
                            text:'${tmp.name}',
                            listeners : {
                                'click' : function(node, event) {
                                    <c:if test="${!empty tmp.panelName}">
                                        callWeb(node, event, '',${tmp.panelName})
                                    </c:if>
                                    if(node.hasChildNodes()){
                                        if(this.expanded){
                                            this.collapse();
                                        }else{
                                            this.expand();
                                        }
                                    }
                                }
                            }
                        }));
                        return false;
                   }
                })
            </c:if>
        </c:forEach>
        showPort = new Ext.Viewport({
            enableTabScroll : true,
            layout : 'border',
            modal : true,
            items : [header, main,menu]
        });
        root.expandChildNodes(true);
    </c:if>
});
</script>		
	</body>
</html>
